import { ss } from '@/utils/storage'
import { useUserStore } from '../user'
import { computed } from 'vue'
const LOCAL_NAME = 'settingsStorage'
export interface SettingsState {
  systemMessage: string
  temperature: number
  top_p: number
}

export function defaultSetting(): SettingsState {
  return {
    systemMessage: 'You are ChatGPT, a large language model trained by OpenAI. Follow the user\'s instructions carefully. Respond using markdown.',
    temperature: 0.8,
    top_p: 1,
  }
}

export function getLocalState(): SettingsState {
  const localSetting: SettingsState | undefined = ss.get(LOCAL_NAME)
  return { ...defaultSetting(), ...localSetting }
}

export function setLocalState(setting: SettingsState): void {
  ss.set(LOCAL_NAME, setting)
}

export function removeLocalState() {
  ss.remove(LOCAL_NAME)
}
export function loginOut(): void {
  const dom = document.createElement('div')
  dom.innerText = '登陆过期，请扫码重新登陆...'
  Object.assign(dom.style, {
    padding: "10px 0 10px 20px",
    top: '10px',
    width: '220px',
    background: 'rgb(72, 72, 78)',
    color: '#fff',
    position: "fixed",
    left: '50%',
    boxShadow: '0 3px 6px -4px rgba(0, 0, 0, .24), 0 6px 12px 0 rgba(0, 0, 0, .16), 0 9px 18px 8px rgba(0, 0, 0, .10)'
  });
  document.body.append(dom)
  setTimeout(() => {
    dom.remove()
  }, 3000);
  localStorage.removeItem('flag')
  localStorage.removeItem('token')
  const userStore = useUserStore();
  const userInfo = computed(() => userStore.userInfo);

  userStore.updateUserInfo({
    ...userInfo.value,
    showModel: true
  });
}
